export function dictListFormat(dictList: API.Dict[]): System.DictDefined {
  return dictList.reduce<System.DictDefined>(
    (dictDefined, item) => {
      // 暂时屏蔽禁用的状态
      if (item.value && item.status === 0) {
        dictDefined.valueEnum[item.value] = {
          text: item.label,
          status: item.color,
          disabled: item.status !== 0,
        };
        dictDefined.tagValueEnum[item.value] = {
          text: item.label,
          tagColor: item.color,
          disabled: item.status !== 0,
        };
        dictDefined.options.push({
          label: item.label,
          value: item.value,
          disabled: item.status !== 0,
        });
        dictDefined.numOptions.push({
          label: item.label,
          value: Number(item.value),
          disabled: item.status !== 0,
        });
      }

      return dictDefined;
    },
    { valueEnum: {}, tagValueEnum: {}, options: [], numOptions: [] },
  );
}

/**
 * 数据字典列表转数据字典组
 * @param dictList 数据字典列表
 * @returns 数据字典组
 */
export function dictListToGroup(dictList: API.Dict[]): API.DictGroup {
  const tempGroup = dictList.reduce<Map<string, API.Dict[]>>((dictGroup, item) => {
    // 暂时屏蔽禁用状态
    if (item.dictType && item.status === 0) {
      const dictTypeList = dictGroup.get(item.dictType) || [];
      dictTypeList.push(item);
      dictGroup.set(item.dictType, dictTypeList);
    }
    return dictGroup;
  }, new Map());
  const dictGroup: API.DictGroup = {};
  tempGroup.forEach((list, key) => {
    dictGroup[key] = dictListFormat(list);
  });
  return dictGroup;
}
